const config = useRuntimeConfig()
console.log('Base URL:', config.public.baseURL);

const token = ref()

export const useToken = () => {
    return useState<string>('token', () => {
        if (!token.value) {
            getToken();
        } else {
            
            return token.value
        }
    });
};

export const getToken = async () => {
    const { data } = await useFetch('/api/public/token', {
        baseURL: `${config.public.baseURL}`,
    })
    console.log('data:', data.value);
    if (data.value) {
        token.value = data.value as string;
        useToken().value = token.value;
        return token.value;
    }
};
